import { kgjHttp as http } from '@/services/http';
import type { RoleListResult, AccountListResult, AccountReqParam, AddRoleDto, UpdateRoleDto, AllRoleFuncListResult, UpdateAccountDto } from '@/types/api/kgj/auth';
import type { SortAndLimit, ListResult } from '@/types/api/common';

/** 岗位管理 - 获取岗位权限列表 */
export const getRoleList = (payload: { data: any; params: SortAndLimit }) =>
  http<ListResult<RoleListResult>, SortAndLimit>({
    url: '/api/permission/role/list',
    method: 'post',
    ...payload
  });
/** 岗位管理 - 切换岗位状态 */
export const toggleRoleStatus = (data: { role_id: number; is_frozen: boolean }) =>
  http({
    url: '/api/permission/role/frozen',
    method: 'post',
    data
  });
/** 岗位管理 - 新增岗位 */
export const addRole = (data: AddRoleDto) =>
  http({
    url: '/api/permission/role/add',
    method: 'post',
    data
  });
/** 岗位管理 - 更新岗位 */
export const updateRole = (data: UpdateRoleDto) =>
  http({
    url: '/api/permission/role/modify',
    method: 'post',
    data
  });
/** 岗位管理 - 删除岗位 */
export const removeRole = (data: {role_id: number;}) =>
  http({
    url: '/api/permission/role/remove',
    method: 'post',
    data
  });
/** 岗位管理 - 获取所有权限 */
export const getRoleFuncList = () =>
  http<ListResult<AllRoleFuncListResult>>({
    url: '/api/permission/role/func/list',
    method: 'get'
  });
/** 账号管理 - 获取账号列表 */
export const getAccountList = (payload: { data: AccountReqParam; params: SortAndLimit }) =>
  http<ListResult<AccountListResult>, AccountReqParam, SortAndLimit>({
    url: '/api/permission/account/list',
    method: 'post',
    ...payload
  });
/** 账号管理 - 切换账号状态 */
export const toggleAccountStatus = (data: { user_id: number; is_frozen: boolean }) =>
  http({
    url: '/api/permission/account/frozen',
    method: 'post',
    data
  });
/** 账号管理 - 获取岗位列表 */
export const getAccountRoleList = () =>
  http({
    url: '/api/permission/account/role/list',
    method: 'get'
  });
/** 账号管理 - 更新账号信息 */
export const updateAccount = (data: UpdateAccountDto) =>
  http({
    url: '/api/permission/account/modify',
    method: 'post',
    data
  });
